#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@File: scheduled_tasks.py
@Author: lijk34925 
@Date: 2024/4/11 16:26
@desc: 运行任务，刷新缓存
"""
import json

from qturboframe.lib.utils.variable import Variable

from CommonScripts.index_rule_cal import indexJobAction
from BladeFerm.Lib.Common import logger

BladeVariable = Variable()


def run_refresh_task_cache(input_data=None, ui_expect=None):
    """
    刷新rcce缓存信息
    :param input_data:
        - server: 服务名称，amlrc，amlls 等等，为空时刷新所有服务的缓存；不为空刷新公共和对应模块的缓存
    :param ui_expect:
    :return:
    """
    env = BladeVariable.get_variable('varg_db_type')
    server_name = input_data.get('server', 'amlrc,amlls')
    task_params = {
            "module_no_list": {"name": "module_no_list", "value": server_name, "custom": True, "direct": "", "index": 0}
        }
    input_data_params = {
        'jobName': 'RefreshRcceCacheJob',
        'taskParam': json.dumps(task_params),
        'env': env
    }
    indexJobAction(input_data=input_data_params, ui_expect={'flag': True})
    logger.info(f"RefreshRcceCacheJob finished with {input_data_params}")
    BladeVariable.set_variable("varg_refresh_cache_flag", "TRUE")  # 更新任务编号